<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
    <title>泥头车企业管理11</title>
</head>
<body>
<div class="datagrid-header" id="corp-grid-toolbar" style="width: 100%;">
    <table class="datagrid-htable" border="0" cellspacing="0" cellpadding="0" style="width:100%;">
        <tr class="datagrid-header-row" style="height: 40px;">
            <td colspan="6" align="left" style="border-style: solid;">
                <a href="javascript:void(0)" id="corp-grid-add" class="easyui-linkbutton" data-options="iconCls:'icon-add'">增加</a>
                <a href="javascript:void(0)" id="corp-grid-delete" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
                <a href="javascript:void(0)" id="corp-grid-edit" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">编辑</a>
                <a href="javascript:void(0)" id="corp-grid-search" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
            </td>
        </tr>
    </table>
</div>

<table id="corp-grid"></table>

<div id="corp-menu" class="easyui-menu" style="width:160px;">
    <div id="corp-menu-view" data-options="iconCls:'icon-search'">查看</div>
    <div id="corp-menu-delete" data-options="iconCls:'icon-remove'">删除</div>
    <div data-options="iconCls:'icon-edit'">
        <span>编辑</span>
        <div>
            <div id="corp-menu-info" data-options="iconCls:'icon-info'">企业信息</div>
            <div id="corp-menu-state" data-options="iconCls:'icon-state'">有效状态</div>
            <div id="corp-menu-area" data-options="iconCls:'icon-area'">实际经营区域</div>
        </div>
    </div>
</div>

<script type="text/javascript">
    function func(){
        var vs = $('select  option:selected').val();
        alert(vs);
    }
    $(function(){
        $("#corp-grid").datagrid({
            title:"企业管理",
            toolbar:"#corp-grid-toolbar",
            border:false,
            fit:true,
            width:$(window).width()-252,
            columns:[[
                {field:"ckb",checkbox:true},
                {field:"id",title:"id",width:200,halign:"center",align:"center",resizable:true,sortable:true},
                {field:"departmentNum",title:"部门编码",width:200,halign:"center",align:"center",resizable:true},
                {field:"departmentName",title:"部门名称",width:80,align:"center",resizable:false},
                {field:"createTime",title:"创建时间",width:80,align:"center",resizable:false,formatter:function(value,row,index){
                	if (row.createTime){
    					//格式化时间,formatDateTime在 DataUtil.js文件中
    					return formatDateTime(row.createTime);
    				} else {
    					return row.createTime;
    				}	
                }
                },
                {field:"updateTime",title:"修改时间",width:80,align:"center",resizable:false,formatter:function(value,row,index){
                	if (row.createTime){
    					//格式化时间,formatDateTime在 DataUtil.js文件中
    					return formatDateTime(row.createTime);
    				} else {
    					return row.createTime;
    				}	
                }
                	},
                {field:"createName",title:"创建人",width:80,align:"center",resizable:false},
                {field:"updateName",title:"修改人",width:80,align:"center",resizable:false}
            ]],
            //striped:true,
            fitColumns:true,
            //autoRowHeight:true,
            rownumbers:false,
            singleSelect:false,
            ctrlSelect:true,
            pagination:true,
            pageSize:10,
            pageList:[5,10,15,20,25,30],
            sortName:"corpId",
            sortOrder:"desc",
            url:"departmentServlet.do?method=query",
            method:"get",
            loadMsg:"加载数据中，请稍后",
            onDblClickRow:function(rowIndex, rowData){
                var selTr = $("#corp-grid").datagrid("getSelections");
                openDialog({
                    type:"view",
                    title:"部门管理",
                    width:800,
                    height:400,
                    maximizable:true,
                    href:"department/getDepartment?id="+selTr[0].id
                });
            },
            onRowContextMenu:function(e, rowIndex, rowData){
                e.preventDefault();

                $(this).datagrid("unselectAll");

                $(this).datagrid("selectRow", rowIndex);

                $("#corp-menu").menu("show",{
                    left:event.pageX,
                    top:event.pageY
                });
            }
        }).datagrid("columnMoving")
                .datagrid("columnHiding");


        //相关功能按钮事件
        $("#corp-grid-search").click(function(){
            $("#corp-grid").datagrid("load",{
                corpId:$("#corpId").val(),
                linkedCorpId:$("#linkedCorpId").val(),
                actOpeArea:$("#actOpeArea").val(),
                ifLocal:$("#ifLocal").val(),
                state:$("#state").val()
            });
        });

        $("#corp-grid-add").click(function(){
            openDialog({
                title:"部门管理",
                width:800,
                height:260,
                maximizable:false,
                href:"html/department/departmentAdd.html"
            });
        });

        $("#corp-grid-delete").click(function(){
            var selTr = $("#corp-grid").datagrid("getSelections");

            if(selTr.length == 0){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:"请至少选择1条记录"
                });
            }else{
                var strIds = "";
                //拼接字符串，这里也可以使用数组，作用一样
                for (var i = 0; i < selTr.length; i++) {
                    strIds += selTr[i].id + "";
                }
                $.ajax({
                    url :'departmentServlet.do?method=delete&ids='+strIds,
                   
                    dataType : 'json',
                    type : 'delete',
                    success : function(data) {
                     	if(data.resultCode=="1"){
	                        Messager.show({
	                            title:"&nbsp;",
	                            content:"删除成功"
	                        });
	                        $("#corp-grid-search").click();
                    	}else{
                    		 Messager.show({
 	                            title:"&nbsp;",
 	                            content:data.resultMessage
 	                        });
                    	}
                    },
                    //400 500,505异常进入,不是json类型的数据
                    error : function(data) {
                        Messager.show({
                            title:"&nbsp;",
                            content:"删除失败"
                        });
                    }
                });
            }
        });

        $("#corp-grid-edit").click(function(){
            var selTr = $("#corp-grid").datagrid("getSelections");

            var infoMsg = null;

            infoMsg = selTr.length < 1 ? "请选择一条记录" : (selTr.length > 1 ? "最多只能选择一条记录" : null);

            if(null != infoMsg){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:infoMsg
                });
            }else{
                openDialog({
                    title:"管理信息编辑",
                    width:800,
                    height:360,
                    maximizable:false,
                    queryParams: { id: selTr[0].id},//设置了一个属性queryParams
                    href:"html/department/departmentAddEdit.html"
                });
            }
        });

        $("#corp-grid-area").click(function(){
            var selTr = $("#corp-grid").datagrid("getSelections");

            var infoMsg = null;

            infoMsg = selTr.length < 1 ? "请选择一条记录" : (selTr.length > 1 ? "最多只能选择一条记录" : null);

            if(null != infoMsg){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:infoMsg
                });
            }else{
                openDialog({
                    title:"泥头车企业实际经营区域编辑",
                    width:500,
                    height:280,
                    maximizable:false,
                    href:"BaseInfo/Corp/CorpAreaEdit.html"
                });
            }
        });

        $("#corp-grid-state").click(function(){
            var selTr = $("#corp-grid").datagrid("getSelections");

            var infoMsg = null;

            infoMsg = selTr.length < 1 ? "请选择一条记录" : (selTr.length > 1 ? "最多只能选择一条记录" : null);

            if(null != infoMsg){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:infoMsg
                });
            }else{
                openDialog({
                    title:"泥头车企业有效状态编辑",
                    width:500,
                    height:320,
                    maximizable:false,
                    href:"BaseInfo/Corp/CorpStateEdit.html"
                });
            }
        });


        //菜单相关按钮事件
        $("#corp-menu-view").click(function(){
            new($("#corp-grid").datagrid("options").onDblClickRow);
        });

        $("#corp-menu-delete").click(function(){
            $("#corp-grid-delete").click();
        });

        $("#corp-menu-info").click(function(){
            $("#corp-grid-edit").click();
        });

        $("#corp-menu-area").click(function(){
            $("#corp-grid-area").click();
        });

        $("#corp-menu-state").click(function(){
            $("#corp-grid-state").click();
        });
    });
</script>
</body>
</html>